<template>
	<sc-table-select-gdshop :style="tableStyle" v-model="defaultValue" :apiObj="apiObj" @change="dataChange"
							:table-width="tableWidth" :tableHeight="tableHeight" multiple :props="excludeTableProps">
		<template #header="{form, submit}">
			<el-form :inline="true" :model="form">
				<el-form-item label="商品名称">
					<el-input v-model="form.goods_name" clearable placeholder="商品名称关键词"/>
				</el-form-item>
				<el-form-item label="商品分类">
					<el-cascader
						v-model="form.category_id"
						:options="shopCategorys"
						:props="{
							value: 'id',
							label: 'cat_name',
							children: 'children',
							emitPath: false
						}"
						clearable
					/>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="submit">查询</el-button>
				</el-form-item>
			</el-form>
		</template>
		<el-table-column prop="id" label="ID" width="40"></el-table-column>
		<el-table-column prop="user" label="商品" align="left">
			<template #default="scope">
				<goods-info-item :row="scope.row" :baseUrl="baseUrl"/>
			</template>
		</el-table-column>
		<el-table-column prop="price" label="价格" width="100">
			<template #default="scope">
				<div class="goods-info page-shop-goods-price-box">
					<div class="price">
						<div>{{ getMoneyByMinute(scope.row.min_price) }}</div>
						<div v-show="scope.row.min_price != scope.row.max_price">
							{{ getMoneyByMinute(scope.row.max_price) }}
						</div>
					</div>
				</div>
			</template>
		</el-table-column>
		<el-table-column prop="stock" label="库存" width="100"/>
		<el-table-column prop="status" label="状态" width="80">
			<template #default="scope">
				{{ scope.row.status == 1 ? "上架" : "仓库" }}
			</template>
		</el-table-column>
	</sc-table-select-gdshop>
</template>

<script>
export default {
	name: "excludeGoodsBox",
	props: {
		baseUrl: {type: String, default: ''},
		modelValue: null,
		tableHeight: {type: Number, default: 400},
		tableWidth: {type: Number, default: 1000},
		tableStyle: {type: Object, default() {
			return {
				'width': '1000px',
				'height': '500px',
			}
		}}
	},
	data() {
		return {
			exclude_goods_ids: [],
			shopCategorys: [],
			defaultValue: [],
			apiObj: this.$API.shop.goods,
			excludeTableProps: {
				label: 'goods_name',
				value: 'id',
				keyword: "keyword"
			},
		}
	},
	watch: {
		modelValue:{
			handler(){
				this.defaultValue = this.modelValue
			},
			deep: true
		}
	},
	mounted() {
		this.getsShopCategorys()
	},
	methods: {
		setExcludeGoodsIds(excludeGoodsIds) {
			this.$nextTick(function () {
				this.$API.shop.goodsActivity.getExcludeGoodsSelects({ids:excludeGoodsIds}).then(res => {
					console.log(res);
					if (res.code === 0) {
						if (res.data) {
							this.dataChange(res.data);
						}
					}
					else {
						this.$message.error(res.message)
					}
				})
			})
		},
		dataChange(data) {
			this.$emit('update:modelValue', data);
			this.$emit('change', data);
		},
		getsShopCategorys() {
			this.$API.shop.category
				.list({
					type_str: "shop"
				})
				.then((res) => {
					this.shopCategorys = this.$TOOL.deepTree(res.data, "parent_id");
				});
		},
		getMoneyByMinute(_val) {
			return this.$TOOL.getMoneyByMinute(_val);
		},
	}
}
</script>

<style scoped>

</style>
